package cn.lan.scau_hotel_service.service.impl;

import cn.lan.scau_hotel_service.entity.Room;
import cn.lan.scau_hotel_service.entity.RoomType;
import cn.lan.scau_hotel_service.repository.RoomRepository;
import cn.lan.scau_hotel_service.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    RoomRepository roomRepository;


    @Override
    public Room getRoomById(int id) {
        return roomRepository.getRoomById(id);
    }

    @Override
    public boolean saveRoom(Room room) {
        return roomRepository.save(room)!=null;
    }

    @Override
    @Transactional
    public boolean deleteRoomById(int id) {
        return roomRepository.deleteRoomById(id)!=0;
    }

    public List<Room> findAll(){
        return roomRepository.findAll();
    }

    @Override
    public int countByCanRentTrue() {
        return roomRepository.countByCanRentTrue();
    }

    @Override
    public int countByIsRentTrue() {
        return roomRepository.countByRentTrue();
    }

    @Override
    public int countByCanRentTrueAndIsRentFalse() {
        return roomRepository.countByCanRentTrueAndRentFalse();
    }

    @Override
    public int countByRoomTypeCanRentTrueAndIsRentFalse(RoomType roomType) {
        return roomRepository.countByRoomTypeAndCanRentTrueAndRentFalse(roomType);
    }

    @Override
    public List<Room> findByCanRentTrueAndIsRentFalse() {
        return roomRepository.findRoomsByCanRentTrueAndRentFalse();
    }

    @Override
    public List<Room> findByCanRentTrue() {
        return roomRepository.findRoomsByCanRentTrue();
    }

    @Override
    public List<Room> getRoomsByRoomTypeAndCanRentTrueAndIsRentFalse(RoomType roomType) {
        return roomRepository.getRoomsByRoomTypeAndCanRentTrueAndRentFalse(roomType);
    }
}
